﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 通讯录
{
    public partial class Form4 : Form
    {
        int sortkey;
        int flag;

        public Form4()
        {
            InitializeComponent();
            sortkey = 0;
            flag = -1;
        }

        private void downsortCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            if(downsortCheckBox.Checked)
            {
                upsortCheckBox.Checked = false;
            }
            else
            {
                upsortCheckBox.Checked = true;
            }
        }

        private void upsortCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            if (upsortCheckBox.Checked)
            {
                downsortCheckBox.Checked = false;
            }
            else
            {
                downsortCheckBox.Checked= true;
            }
        }

        private int setSortKey()
        {
            List<RadioButton> radios = new List<RadioButton>();
            radios.Add(nameRadioButton);
            radios.Add(sexRadioButton);
            radios.Add(teleRadioButton);
            radios.Add(addrRadioButton);
            radios.Add(ageRadioButton);
            radios.Add(birthdateRadioButton);
            
            foreach(RadioButton radio in radios)
            {
                if (radio.Checked)
                {
                    sortkey = radios.IndexOf(radio) + 1;
                }
            }

            return sortkey;
        }

        private int setFlag()
        {
            if (upsortCheckBox.Checked)
            {
                flag = 1;
            }
            else if (downsortCheckBox.Checked)
            {
                flag = 0;
            }

            return flag;
        }

        public int getSortKey
        {
            get
            {
                return sortkey;
            }
        }

        public int getFlag
        {
            get
            {
                return flag;
            }
        }

        private void submitButton_Click(object sender, EventArgs e)
        {
            setSortKey();
            setFlag();
            this.DialogResult = DialogResult.OK;
        }
    }
}
